package com.mobimagic.lockscreen.view;

import android.content.Context;
import android.content.res.Resources;
import android.util.DisplayMetrics;
import android.util.Log;

import com.mobimagic.lockscreen.R;
import com.mobimagic.lockscreen.util.ScreenUtil;

public class LayoutData {
    public static final float IMG_WIDTH_HEIGHT = 1.918f;
    public static LayoutData instance;

    private float density;
    private float oneAdCardScrollSlop;

    private int slidLockHeight;
    private int adCardHeight;
    /**
     * 横线离底部的距离
     */
    private int lineBottom;

    /**
     * scrollview的高度
     */
    private int scrollViewHeight;
    private int waveTop;

    private int topFadeViewMarginBottom;

    private int peakHeight;
    private float headHeight;
    private int showHeadHeight;

    private int overScrollHeight;
    private int minScrollY;
    private float slidDelete;
    private int mCardMarginLeft;
    private int bottomFadeHeight;
    private int topFadeHeight;
    private int cardDividerHeight;

    public synchronized static void create(Context context) {
        if (instance == null) {
            instance = new LayoutData(context);
        }
    }

    public static LayoutData getInstance() {
        return instance;
    }

    private LayoutData(Context context) {

        DisplayMetrics display = context.getResources().getDisplayMetrics();
        Resources res = context.getResources();
        if (MobileChargingView.DEBUG) {
            Log.d(MobileChargingView.TAG, "screeen width=" + display.widthPixels + "screen height="
                    + display.heightPixels);
        }
        int screenwidth = display.widthPixels;
        int scrollViewWidth = screenwidth - 2 * ScreenUtil.dpToPxInt(context, 8);
        headHeight = res.getDimension(R.dimen.charging_card_head_height);
        adCardHeight = (int) (scrollViewWidth / IMG_WIDTH_HEIGHT + headHeight);
        int gradientHeight = ScreenUtil.dpToPxInt(context, 16);
        int calculateHeigth = (int) (adCardHeight + gradientHeight);
        int givenHeight = ScreenUtil.dpToPxInt(context, 310);
        if (display.widthPixels == 480) {
            givenHeight = ScreenUtil.dpToPxInt(context, 260);
        }
        if (MobileChargingView.DEBUG) {
            Log.i(MobileChargingView.TAG, "calculateHeigth==" + calculateHeigth + "givenHeight==" + givenHeight);
        }
        scrollViewHeight = calculateHeigth >= givenHeight ? calculateHeigth : givenHeight;

        slidLockHeight = (int) res.getDimension(R.dimen.slid_unlock_height);
        waveTop = (int) res.getDimension(R.dimen.wave_top);
        peakHeight = (int) res.getDimension(R.dimen.charging_wave_peek_height);
        lineBottom = (int) (res.getDimension(R.dimen.line_scrollview_top_margin) + scrollViewHeight + slidLockHeight);

        float height = res.getDimension(R.dimen.top_fade_height);
        topFadeViewMarginBottom = (int) (scrollViewHeight + slidLockHeight - height);
        oneAdCardScrollSlop = res.getDimension(R.dimen.one_ad_card_scroll_slop);
        showHeadHeight = (int) res.getDimension(R.dimen.charging_show_head_card_height);
        overScrollHeight = (int) res.getDimension(R.dimen.over_scroll);
        minScrollY = scrollViewHeight - overScrollHeight;
        slidDelete = res.getDimension(R.dimen.slid_delete);
        mCardMarginLeft = (int) res.getDimension(R.dimen.card_margin_left);
        bottomFadeHeight = (int) res.getDimension(R.dimen.bottom_fade_height);
        topFadeHeight = (int) res.getDimension(R.dimen.top_fade_height);
        density = res.getDisplayMetrics().density;
        cardDividerHeight = (int) res.getDimension(R.dimen.card_divider_height);
    }

    public int getCardDividerHeight() {
        return cardDividerHeight;
    }

    public float getDensity() {
        return density;
    }

    public int getTopFadeHeight() {
        return topFadeHeight;
    }

    public int getBottomFadeHeight() {
        return bottomFadeHeight;
    }

    public float getSlidDelete() {
        return slidDelete;
    }

    /**
     * 显示最上端的overScroll位置
     */
    public int getMinScrollY() {
        return minScrollY;
    }

    public int getOverScrollHeight() {
        return overScrollHeight;
    }

    public int getTopFadeViewMarginBottom() {
        return topFadeViewMarginBottom;
    }

    public int getLineBottom() {
        return lineBottom;
    }

    public int getScrollViewHeight() {
        return scrollViewHeight;
    }

    public int getAdCardHeight() {
        return adCardHeight;
    }

    public float getOneAdCardScrollSlop() {
        return oneAdCardScrollSlop;
    }

    public int getSlidLockHeight() {
        return slidLockHeight;
    }

    public int getWaveTop() {
        return waveTop;
    }

    public int getPeakHeight() {
        return peakHeight;
    }

    public int getShowHeadHeight() {
        return showHeadHeight;
    }

    public int getCardMarginLeft() {
        return mCardMarginLeft;
    }

}
